﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;


[assembly: log4net.Config.DOMConfigurator(Watch = true)]
namespace Mall.Infrastructure.Log
{
    /// <summary>
    /// 应用程序扩展
    /// </summary>
    public static class LogManageExtensions
    {
        /// <summary>
        /// 获取日志记录入口
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static LogManage GetLogManage(this AppDomain app)
        {
           return  LogManage.GetInstance();
        }

        /// <summary>
        /// 日志管理(单例模式)
        /// </summary>
        public class LogManage
        {

            /// <summary>
            /// 唯一存在的对象
            /// </summary>
            private static LogManage Instance;

            /// <summary>
            /// 上锁对象
            /// </summary>
            private static readonly object _object = new object();

            /// <summary>
            /// 错误日志记录对象
            /// </summary>
            private ILog Log;


            /// <summary>
            /// 唯一获取对象的入口
            /// </summary>
            /// <returns></returns>
            public static LogManage GetInstance()
            {
                if (Instance == null)
                {
                    lock (_object)
                    {
                        if (Instance == null)
                        {
                            Instance = new LogManage();
                        }
                    }
                }
                return Instance;
            }

            /// <summary>
            /// 初始化
            /// </summary>
            private LogManage()
            {
                Log = log4net.LogManager.GetLogger("InfoAppender");
            }

            public void Error(string error)
            {
                Log.Error(error);
            }

            public void Info(string info)
            {
                Log.Info(info);
            }
        }
    }

}
